﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Detail : System.Web.UI.Page
{
    MyDataDataContext db = new MyDataDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)//用户未登录，返回登录界面
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            //页面首次加载且商品ID不为空
            if (!IsPostBack & Request.QueryString["GoodsID"] != null)
            {

                //获取要出售信息的记录
                var goods = (from r in db.SaleOfGoods
                             where r.GoodsID == Request.QueryString["GoodsID"]
                             select r).First();


                //显示商品信息
                //商品图片路径不为空，显示头像

                Image1.ImageUrl = goods.GoodsPicture;

                //商品名称
                GoodsName.Text = goods.GoodsName;
                //商品描述
                GoodsDescription.Text = goods.GoodsDescription;
                //商品价格
                Price.Text = Convert.ToString(goods.Price);
                //商品分类
                Type.SelectedValue = goods.Type;
                ReleaseTime.Text = goods.ReleaseTime;

                //获取商品分类信息
                var results = from r in db.GoodsType
                              select new
                              {
                                  r.GoodsTypeName
                              };//映射需要显示的字段

                //设置DropDownList控件的数据源
                Type.DataSource = results;
                //调用DataBind()方法显示数据
                Type.DataBind();

            }

        }
       
    }

    protected void Back(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");

    }
    //跳转到相应的购买页面，将GoodsID传递给Buy页面
    protected void Buy(object sender, EventArgs e)
    {
        Response.Redirect("Buy.aspx?GoodsID=" + Request.QueryString["GoodsID"]);
    }
}